package com.aat.dxfy.protobuf.test1;

import java.net.Socket;

import com.aat.dxfy.protobuf.test1.proto.Mobile;

public class ClientTest {

	private static Socket socket;

	public static void main(String[] args) throws Exception {
		socket = new Socket("127.0.0.1", 3030);
		Mobile.MobilePhone.Builder builder = Mobile.MobilePhone.newBuilder();
		Mobile.Hardware.Builder hardware = Mobile.Hardware.newBuilder();
		hardware.setRam(2).setRom(16).setSize(5);
		builder.setHardware(hardware).setBrand("Apple").addSoftware("camera").addSoftware("tecent")
				.addSoftware("browser").addSoftware("player");
		byte[] messageBody = builder.build().toByteArray();

		int headerLen = 1;
		byte[] message = new byte[headerLen + messageBody.length];
		message[0] = (byte) messageBody.length;
		System.arraycopy(messageBody, 0, message, 1, messageBody.length);
		System.out.println("msg len:" + message.length);
		socket.getOutputStream().write(message);
	}

}
